package com.cddx.logistics.controller;

import com.cddx.logistics.domain.dto.InventoryQueryDTO;
import com.cddx.logistics.domain.dto.StockOperationQueryDTO;
import com.cddx.logistics.domain.vo.InventoryVO;
import com.cddx.logistics.domain.vo.LineStatsVO;
import com.cddx.logistics.domain.vo.StorageLocationVO;
import com.cddx.logistics.domain.vo.WarehouseVO;
import com.cddx.logistics.service.InventoryService;
import com.cddx.logistics.util.model.R;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 库存管理
 */
@RestController
@RequestMapping("/inventory")
public class InventoryController {
    @Resource
    private InventoryService inventoryService;

    /**
     * 查询库存信息分页
     * @param queryDTO 查询条件封装对象
     * @return 分页查询结果
     */
    @GetMapping("/queryPage")
    public R queryPage(InventoryQueryDTO queryDTO) {
        PageInfo<InventoryVO> pageInfo = inventoryService.queryPage(queryDTO);
        return R.ok(pageInfo);
    }

    /**
     * 获取所有仓库信息
     * @return 仓库信息列表
     */
    @GetMapping("/listAllWarehouses")
    public R listAllWarehouses() {
        List<WarehouseVO> list = inventoryService.listAllWarehouses();
        return R.ok(list);
    }

    /**
     * 获取所有库位列表
     * @return 库位信息列表
     */
    @GetMapping("/listAllStorageLocations")
    public R listAllStorageLocations() {
        List<StorageLocationVO> list = inventoryService.listAllStorageLocations();
        return R.ok(list);
    }

    /**
     * 根据仓库ID获取库位列表
     * @param warehouseId 仓库ID
     * @return 库位列表
     */
    @GetMapping("/listStorageLocationsByWarehouse")
    public R listStorageLocationsByWarehouse(@RequestParam Long warehouseId) {
        List<StorageLocationVO> list = inventoryService.listStorageLocationsByWarehouse(warehouseId);
        return R.ok(list);
    }

    /**
     * 获取仓库容积统计数据
     * @return 各仓库容积数据
     */
    @GetMapping("/warehouseCapacityStats")
    public R getWarehouseCapacityStats() {
        List<Map<String, Object>> stats = inventoryService.getWarehouseCapacityStats();
        return R.ok(stats);
    }


}